import axios from 'axios';
import Config from 'react-native-config';
axios.defaults.baseURL = Config.API_URL;

export interface GetHttpConfig {
  url: string;
  params?: object;
}
export const get = async (config: GetHttpConfig) => {
  const {url, params} = config;
  const res = await axios.get(url, {
    ...params,
    // ...paramsConfig,
  });
  return res;
};

export interface PostHttpConfig {
  url: string;
  data?: object;
}
export const post = async (config: PostHttpConfig) => {
  const {url, data} = config;
  const res = await axios.post(url, {
    ...data,
  });
  return res;
};

axios.interceptors.request.use(
  config => {
    // console.log('请求config', config);
    return config;
  },
  error => {
    return Promise.reject(error);
  },
);

axios.interceptors.response.use(
  response => {
    // console.log('响应数据response', response);
    return response.data;
  },
  error => {
    return Promise.reject(error);
  },
);
